﻿using MediatR;
using Warehouse.API.Applcation.Command.OutBoundCommand;
using Warehouse.Infrstructre.Interface;

namespace Warehouse.API.Applcation.CommandHandlers.OutShipCommandHandlers
{
    public class DelOutShipCommandHandlers:IRequestHandler<DelOutShipCommand,int>
    {

        private readonly IOutShipRepository _outShipRepository;

        private readonly IOutProductRepository _outProductRepository;

        public DelOutShipCommandHandlers(IOutShipRepository outShipRepository, IOutProductRepository outProductRepository)
        {
            _outShipRepository = outShipRepository;
            _outProductRepository = outProductRepository;
        
        }

        public async Task<int> Handle(DelOutShipCommand request, CancellationToken cancellationToken)
        {
            var list = (await _outShipRepository.GetAllAsyns()).Where(x => request.ids.Contains(x.OutShipId));

            foreach (var item in list)
            {
                if (item != null)
                {
                    item.IsDel = true;
                    item.DelName = request.DelName;
                    item.DelTime = DateTime.Now;
                    await _outShipRepository.UpdateAsync(item);
                    
                }
                else
                {
                    return -1;
                }
              
            }
            return 1;
           
        }



    }
}
